package com.shihb.udfs;

import java.security.MessageDigest;
import org.apache.hadoop.hive.ql.exec.UDF;


/**
 *Description:
 *Version:1.0.0
 *@author shihb
 *@date 2020/7/23 9:39
 */
public class MD5 extends UDF {

  public static String evaluate(String value) {
    StringBuilder sb = new StringBuilder();
    try {
      MessageDigest messageDigest = MessageDigest.getInstance("MD5");
      byte[] bytes = messageDigest.digest(value.getBytes());
      for (int i = 0; i < bytes.length; i++) {
        int tempInt = bytes[i] & 0xff;
        if (tempInt < 16) {
          sb.append(0);
        }
        sb.append(Integer.toHexString(tempInt));
      }
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    return sb.toString();
  }


  public static void main(String[] args) {
    String hello = "Dashboard";
    System.out.println("MD5加密后的结果：" + evaluate(hello));
  }
}
